package com.motu.vertx.module.utility.commondata;

import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

public class WordManager {
    /**
     * 根据语言类型获取文字
     */
    public static String getWordByLanguage(String word, int language) {
        if (language == 0){
            return word;
        }
        JsonArray array;
        try{
            array = new JsonArray(word);
        } catch(Exception e){
            return word;
        }
        for (int i = 0,size = array.size();i <size;i++){
            JsonObject obj = array.getJsonObject(i);
            if (obj.containsKey("type") && obj.containsKey("word")) {
                if (obj.getInteger("type") == language){
                    return obj.getString("word");
                }
            }
        }
        return "";
    }

}
